home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / RVGD9V (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  8.4 KB  |  217 lines

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import com.sun.java.swing.Action;
  4. import com.sun.java.swing.Icon;
  5. import com.sun.java.swing.JComponent;
  6. import com.sun.java.swing.JList;
  7. import com.sun.java.swing.JPanel;
  8. import com.sun.java.swing.UIManager;
  9. import com.sun.java.swing.event.ListSelectionListener;
  10. import com.sun.java.swing.plaf.FileChooserUI;
  11. import com.sun.java.swing.preview.JFileChooser;
  12. import com.sun.java.swing.preview.filechooser.FileFilter;
  13. import com.sun.java.swing.preview.filechooser.FileView;
  14. import java.awt.BorderLayout;
  15. import java.awt.event.MouseListener;
  16. import java.beans.PropertyChangeEvent;
  17. import java.beans.PropertyChangeListener;
  18. import java.io.File;
  19.  
  20. public abstract class BasicFileChooserUI extends FileChooserUI implements PropertyChangeListener {
  21.    protected Icon directoryIcon = null;
  22.    protected Icon fileIcon = null;
  23.    protected Icon computerIcon = null;
  24.    protected Icon hardDriveIcon = null;
  25.    protected Icon floppyDriveIcon = null;
  26.    protected Icon newFolderIcon = null;
  27.    protected Icon upFolderIcon = null;
  28.    protected Icon homeFolderIcon = null;
  29.    protected Icon listViewIcon = null;
  30.    protected Icon detailsViewIcon = null;
  31.    protected String saveButtonText = null;
  32.    protected String openButtonText = null;
  33.    protected String cancelButtonText = null;
  34.    protected String updateButtonText = null;
  35.    protected String helpButtonText = null;
  36.    protected static String saveButtonToolTipText = null;
  37.    protected static String openButtonToolTipText = null;
  38.    protected static String cancelButtonToolTipText = null;
  39.    protected static String updateButtonToolTipText = null;
  40.    protected static String helpButtonToolTipText = null;
  41.    private Action approveSelectionAction = new ApproveSelectionAction(this);
  42.    private Action cancelSelectionAction = new CancelSelectionAction(this);
  43.    private Action updateAction = new UpdateAction(this);
  44.    private Action newFolderAction = new NewFolderAction(this);
  45.    private Action goHomeAction = new GoHomeAction(this);
  46.    private Action changeToParentDirectoryAction = new ChangeToParentDirectoryAction(this);
  47.    private JFileChooser filechooser = null;
  48.    private AcceptAllFileFilter acceptAllFileFilter = new AcceptAllFileFilter(this);
  49.    protected String fileDescription = "Generic File";
  50.    protected String directoryDescription = "Directory";
  51.    protected BasicDirectoryModel model = null;
  52.    protected BasicFileView fileView = new BasicFileView(this);
  53.    protected JPanel accessoryPanel = null;
  54.  
  55.    public BasicFileChooserUI(JFileChooser b) {
  56.    }
  57.  
  58.    protected void addListeners() {
  59.       this.getFileChooser().addPropertyChangeListener(this.model);
  60.       this.getFileChooser().addPropertyChangeListener(this);
  61.    }
  62.  
  63.    protected MouseListener createDoubleClickListener(JList list) {
  64.       return new DoubleClickListener(this, list);
  65.    }
  66.  
  67.    public ListSelectionListener createListSelectionListener() {
  68.       return new SelectionListener(this);
  69.    }
  70.  
  71.    protected void createModel() {
  72.       this.model = new BasicDirectoryModel(this.getFileChooser());
  73.    }
  74.  
  75.    public abstract void ensureFileIsVisible(File var1);
  76.  
  77.    public FileFilter getAcceptAllFileFilter() {
  78.       return this.acceptAllFileFilter;
  79.    }
  80.  
  81.    public JPanel getAccessoryPanel() {
  82.       return this.accessoryPanel;
  83.    }
  84.  
  85.    public String getApproveButtonText() {
  86.       String buttonText = this.getFileChooser().getApproveButtonText();
  87.       if (buttonText != null) {
  88.          return buttonText;
  89.       } else if (this.getFileChooser().getDialogType() == 0) {
  90.          return this.openButtonText;
  91.       } else {
  92.          return this.getFileChooser().getDialogType() == 1 ? this.saveButtonText : null;
  93.       }
  94.    }
  95.  
  96.    public String getApproveButtonToolTipText() {
  97.       String tooltipText = this.getFileChooser().getApproveButtonToolTipText();
  98.       if (tooltipText != null) {
  99.          return tooltipText;
  100.       } else if (this.getFileChooser().getDialogType() == 0) {
  101.          return openButtonToolTipText;
  102.       } else {
  103.          return this.getFileChooser().getDialogType() == 1 ? saveButtonToolTipText : null;
  104.       }
  105.    }
  106.  
  107.    public Action getApproveSelectionAction() {
  108.       return this.approveSelectionAction;
  109.    }
  110.  
  111.    public Action getCancelSelectionAction() {
  112.       return this.cancelSelectionAction;
  113.    }
  114.  
  115.    public Action getChangeToParentDirectoryAction() {
  116.       return this.changeToParentDirectoryAction;
  117.    }
  118.  
  119.    public String getDialogTitle() {
  120.       return this.getApproveButtonText();
  121.    }
  122.  
  123.    public abstract String getDirectoryName();
  124.  
  125.    public JFileChooser getFileChooser() {
  126.       return this.filechooser;
  127.    }
  128.  
  129.    public abstract String getFileName();
  130.  
  131.    public FileView getFileView() {
  132.       return this.fileView;
  133.    }
  134.  
  135.    public Action getGoHomeAction() {
  136.       return this.goHomeAction;
  137.    }
  138.  
  139.    public BasicDirectoryModel getModel() {
  140.       return this.model;
  141.    }
  142.  
  143.    public Action getNewFolderAction() {
  144.       return this.newFolderAction;
  145.    }
  146.  
  147.    public Action getUpdateAction() {
  148.       return this.updateAction;
  149.    }
  150.  
  151.    public abstract void installComponents();
  152.  
  153.    public void installUI(JComponent c) {
  154.       this.accessoryPanel = new JPanel(new BorderLayout());
  155.       this.filechooser = (JFileChooser)c;
  156.       this.loadIcons();
  157.       this.loadStrings();
  158.       this.createModel();
  159.       this.installComponents();
  160.       this.addListeners();
  161.    }
  162.  
  163.    protected void loadIcons() {
  164.       this.directoryIcon = UIManager.getIcon("FileView.directoryIcon");
  165.       this.fileIcon = UIManager.getIcon("FileView.fileIcon");
  166.       this.computerIcon = UIManager.getIcon("FileView.computerIcon");
  167.       this.hardDriveIcon = UIManager.getIcon("FileView.hardDriveIcon");
  168.       this.floppyDriveIcon = UIManager.getIcon("FileView.floppyDriveIcon");
  169.       this.newFolderIcon = UIManager.getIcon("FileChooser.newFolderIcon");
  170.       this.upFolderIcon = UIManager.getIcon("FileChooser.upFolderIcon");
  171.       this.homeFolderIcon = UIManager.getIcon("FileChooser.homeFolderIcon");
  172.       this.detailsViewIcon = UIManager.getIcon("FileChooser.detailsViewIcon");
  173.       this.listViewIcon = UIManager.getIcon("FileChooser.listViewIcon");
  174.    }
  175.  
  176.    protected void loadStrings() {
  177.       this.saveButtonText = UIManager.getString("FileChooser.saveButtonText");
  178.       this.openButtonText = UIManager.getString("FileChooser.openButtonText");
  179.       this.cancelButtonText = UIManager.getString("FileChooser.cancelButtonText");
  180.       this.updateButtonText = UIManager.getString("FileChooser.updateButtonText");
  181.       this.helpButtonText = UIManager.getString("FileChooser.helpButtonText");
  182.       saveButtonToolTipText = UIManager.getString("FileChooser.saveButtonToolTipText");
  183.       openButtonToolTipText = UIManager.getString("FileChooser.openButtonToolTipText");
  184.       cancelButtonToolTipText = UIManager.getString("FileChooser.cancelButtonToolTipText");
  185.       updateButtonToolTipText = UIManager.getString("FileChooser.updateButtonToolTipText");
  186.       helpButtonToolTipText = UIManager.getString("FileChooser.helpButtonToolTipText");
  187.    }
  188.  
  189.    public abstract void propertyChange(PropertyChangeEvent var1);
  190.  
  191.    public abstract void rescanCurrentDirectory();
  192.  
  193.    public abstract void setDirectoryName(String var1);
  194.  
  195.    public abstract void setFileName(String var1);
  196.  
  197.    protected void uninstallListeners() {
  198.       if (this.getFileChooser() != null) {
  199.          this.getFileChooser().removeAll();
  200.          this.getFileChooser().removePropertyChangeListener(this);
  201.          this.getFileChooser().removePropertyChangeListener(this.model);
  202.       }
  203.  
  204.    }
  205.  
  206.    public void uninstallUI(JComponent c) {
  207.       this.filechooser.removeAll();
  208.       this.uninstallListeners();
  209.       if (this.accessoryPanel != null) {
  210.          this.accessoryPanel.removeAll();
  211.       }
  212.  
  213.       this.filechooser = null;
  214.       this.accessoryPanel = null;
  215.    }
  216. }
  217.